﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace WpfApp_Binding.BindingProperties
{
    public class StringValueConvert : IValueConverter
    {
        /// <summary>
        /// 将数据源到目标的转换方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return $"他的名字叫做{value.ToString()}";
        }

        /// <summary>
        /// 从目标到数据源转换的转换方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (value.ToString())?.Replace("他的名字叫做", "") ?? null;
        }
    }
}
